//
//  DCDetailAddressCell.m
//  Demo
//
//  Created by zhaolin on 2023/1/12.
//

#import "DCDetailAddressCell.h"
#import "DCAuthInfoUIModel.h"


@interface DCDetailAddressCell ()<UITextViewDelegate>

@property (nonatomic, strong) UILabel *placeholder;

@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) DCAuthInfoUIModel *model;

@end

@implementation DCDetailAddressCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier  {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self confiugreUI];
    }
    return self;
}

- (void)configureDataWithModel:(DCAuthInfoUIModel *)model {
    _model = model;
    _placeholder.text = model.placeholder;
}

- (void)confiugreUI {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = [UIColor colorWithString:@"#FFFFFF"];
    UIView *bgView = [UIView new];
    bgView.backgroundColor = [UIColor clearColor];
    bgView.layer.cornerRadius = 8;
    bgView.layer.masksToBounds = YES;
    bgView.layer.borderColor = [UIColor colorWithString:@"#F7F7F7"].CGColor;
    bgView.layer.borderWidth = 1;
    [self.contentView addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(18);
        make.right.mas_equalTo(-18);
        make.top.mas_equalTo(10);
        make.bottom.mas_equalTo(0);
    }];
    
    _textView = [[UITextView alloc] init];
    _textView.textColor = [UIColor colorWithString:@"#1C221B"];
    _textView.backgroundColor = [UIColor clearColor];
    _textView.font = DCFont_PF_Regular(14);
    _textView.delegate = self;
    [bgView addSubview:_textView];
    [_textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(18);
        make.top.mas_equalTo(13);
        make.right.mas_equalTo(-21);
        make.bottom.mas_equalTo(-10);
    }];
    
    _placeholder = [UILabel new];
    _placeholder.textColor = [UIColor colorWithString:@"#C7C7C7"];
    _placeholder.font = DCFont_PF_Light(14);
    [bgView addSubview:_placeholder];
    [_placeholder mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(21);
        make.top.mas_equalTo(16);
    }];
}
- (void)textViewDidChange:(UITextView *)textView {
    self.placeholder.hidden = textView.text.length;
}
- (void)textViewDidEndEditing:(UITextView *)textView {
    self.model.content = textView.text;
    if(self.delegate && [self.delegate respondsToSelector:@selector(detailAddressCellEndEdting:)]) {
        [self.delegate detailAddressCellEndEdting:textView.text];
    }
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
